/*!
 * \file    uvga.h
 * \class   uVGA
 * \brief   TODO
 * FIXME    To slow.
 *
 * \author  Adrien Bougouin <adrien.bougouin@gmail.com>
 */

#ifndef __UVGA_H__
#define __UVGA_H__

#include "WProgram.h"

// usefull delays (milliseconds)
#define AWAKE_DELAY                           1000
#define DELAY_AFTER_CMD                       325

// uVGA answers
#define ACK                                   0x06
#define NAK                                   0x15

// uVGA constants
#define SMALL_SIZE_FONT                       0x00
#define MEDIUM_SIZE_FONT                      0x01
#define LARGE_SIZE_FONT                       0x02
//----------
#define TRANSPARENT_TEXT                      0x01
#define OPAQUE_TEXT                           0x02
//----------
#define NOT_ALIGNED_WRAP                      0x00
#define ALIGNED_WRAP                          0x01

// uVGA commands
#define WAKE_CMD                              0x55
#define ERASE_CMD                             0x45
#define BACKGROUND_CMD                        0x42
#define PUT_PIXEL_CMD                         0x50
#define READ_PIXEL_CMD                        0x52
#define DRAW_CIRCLE_CMD                       0x43
#define DRAW_LINE_CMD                         0x4C
#define FONT_SIZE_CMD                         0x46
#define OPAQUE_TRANSPARENT_TEXT_CMD           0x4F
#define PLACE_FORMATTED_TEXT_CHARACTER_CMD    0x54
#define PLACE_UNFORMATTED_TEXT_CHARACTER_CMD  0x74
#define PLACE_FORMATTED_ASCII_STRING_CMD      0x73

class uVGA {
  private:
    void send_cmd(const char cmd,
                  const char **args,
                  bool need_delay_after_cmd = false) const;
    char uvga_response() const;
  public:
    void begin(const unsigned int baud) const;
    void erase_screen() const;
    void background_color(const char color) const;
    void put_pixel(const short int x,
                   const short int y,
                   const char color) const;
    char read_pixel(const short int x,
                    const short int y,
                    const char color) const;
    void draw_circle(const short int x,
                     const short int y,
                     const char radius,
                     const char color) const;
    void draw_line(const short int x1,
                   const short int y1,
                   const short int x2,
                   const short int y2,
                   const char color) const;
    void font_size(const char font_size) const;
    void opaque_or_transparent_text(const char mode) const;
    void place_formatted_text_character(const char character,
                                        const char column,
                                        const char rom,
                                        const char color) const;
    void place_unformatted_text_character(const char character,
                                          const short int x,
                                          const short int y,
                                          const char color,
                                          const char x_size,
                                          const char y_size) const;
};

#endif

